//
//  LPKHomeDetailView.m
//  Demo-01
//
//  Created by 李平宽 on 2017/1/21.
//  Copyright © 2017年 com.lpk. All rights reserved.
//

#import "LPKHomeDetailCell.h"
#import "Masonry.h"
#import "UIColor+Addition.h"
#import "UILabel+Addition.h"
#import "UIImageView+WebCache.h"
@interface LPKHomeDetailCell ()

/**
 
 标题
 */
@property(nonatomic,strong)UILabel *lab;

/**
 图片
 */
@property(nonatomic,strong)UIImageView *imag;


/**
 内容
 */
@property(nonatomic,strong)UILabel *content;


@end

@implementation LPKHomeDetailCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self setupUI];
    }
    return self;
}

- (void)setupUI{
    UILabel *lab = [UILabel makeLabelText:@"" andTextColor:[UIColor colorWithHex:0x000000] andTextFont:14];
    [self.contentView addSubview:lab];
    [lab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.offset(10);
        make.right.offset(-8);
    }];
    lab.numberOfLines = 0;
    
    UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"placeholderImage"]];
    [self.contentView addSubview: img];
    
    [img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lab.mas_bottom).offset(8);
        make.left.offset(10);
        make.right.offset(-8);
        
    }];
    
    
    UILabel *lun =  [UILabel makeLabelText:@"" andTextColor:[UIColor colorWithHex:0x7686a8] andTextFont:13];
    [self.contentView addSubview:lun];
    [lun mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(img.mas_bottom).offset(8);
        make.left.offset(9);
        make.right.offset(-8);
        make.bottom.offset(-8);
    }];
    lun.numberOfLines = 0;
    _lab = lab;
    _imag = img;
    _content = lun;
    
    

    
}
- (void)setModel:(LPKHomeDetailModel *)model{
    
    _model = model;
    _lab.text = model.title;
    [_imag sd_setImageWithURL:[NSURL URLWithString:model.pic] placeholderImage:[UIImage imageNamed:@"placeholderImage"]];
    if (![model.pic isEqualToString:@""])
    {
        
        CGFloat imgRealW = _imag.image.size.width;
        CGFloat imgRealH = _imag.image.size.height;
        CGFloat imagViewHeight = 200;
        CGFloat imagViewwith = imagViewHeight * imgRealW / imgRealH;
        [_imag sizeToFit];
        [_imag mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.offset(imagViewHeight);
            make.width.offset(imagViewwith);
            make.top.equalTo(_lab.mas_bottom).offset(8);
        }];
        
    }else
    {
        [_imag mas_updateConstraints:^(MASConstraintMaker *make) {
            make.height.width.offset(0);
            make.top.equalTo(_lab.mas_bottom).offset(0);
        }];
    }
    
    _content.text = model.content;
    
}
@end
